/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import Helper.DepartmentHelper;
import Helper.RoomHelper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author hxbien
 */
public class RoomDAO {
     public static ResultSet fillAllRoom(Connection cnn) throws Exception {
        String strSQL = "Select * from tblRoom";
        PreparedStatement stmt = cnn.prepareStatement(strSQL);
        return stmt.executeQuery();
    }

     public static ArrayList<RoomHelper> fillAll(Connection cnn) throws Exception{
        ArrayList<RoomHelper> arrRoomList = new ArrayList<RoomHelper>();
        RoomHelper roomData = null;
        String strSQL = "Select * from tblRoom";
        PreparedStatement stmt = cnn.prepareStatement(strSQL);
        ResultSet rs = stmt.executeQuery();
        while(rs.next()){
            roomData = new RoomHelper();
            roomData.setRoomID(rs.getString("RoomId"));
            roomData.setRoomName(rs.getString("RoomName"));
            arrRoomList.add(roomData);
        }
        return arrRoomList;
    }

      public static ResultSet FillOne(Connection cnn, RoomHelper obj) throws Exception {
        String strSQL = "Select * from tblRoom where RoomID=?";
        PreparedStatement stmt = cnn.prepareStatement(strSQL);
        stmt.setString(1, obj.getDepartmentID());
        return stmt.executeQuery();
    }

      public static boolean checkRoom(Connection cnn, RoomHelper obj) throws Exception {
        boolean check = false;
        String strSQL = "Select * from tblRoom where RoomName=?";
        PreparedStatement stmt = cnn.prepareStatement(strSQL);
        stmt.setString(1, obj.getRoomName());
        ResultSet rs = stmt.executeQuery();
        if(rs.next()){
            check = true;
        }
        return check;
    }

      public static int Insert(Connection cnn, RoomHelper obj) throws Exception{
        String strSQL = "Insert into tblRoom(RoomName,Status,DepartmentId) values(?,?,?)";
        PreparedStatement stmt = cnn.prepareStatement(strSQL);
        stmt.setString(1, obj.getRoomName());
        stmt.setString(2, obj.getRoomStatus());
        stmt.setString(3, obj.getDepartmentID());
        return stmt.executeUpdate();
    }
      

        public static int Update(Connection cnn, RoomHelper obj) throws Exception {
        String strSQL = "update tblRoom set RoomName=?,Status=?,DepartmentId=? where RoomId=?";
        PreparedStatement stmt = cnn.prepareStatement(strSQL);
        stmt.setString(1, obj.getRoomName());
        stmt.setString(2, obj.getRoomStatus());
        stmt.setString(3, obj.getDepartmentID());
        stmt.setString(4, obj.getRoomID());
        return stmt.executeUpdate();
    }
         public static int Delete(Connection cnn, RoomHelper obj) throws Exception{
        String strSQL = "DELETE FROM tblRoom WHERE RoomId = ?";
        PreparedStatement stmt = cnn.prepareStatement(strSQL);
        stmt.setString(1, obj.getDepartmentID());
        return stmt.executeUpdate();
    }
}
